package com.yunsc.order.sevice.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunsc.common.utils.PageResult;
import com.yunsc.media.service.YunscUploadFileService;
import com.yunsc.order.dao.YunscRechargeOrderDao;
import com.yunsc.order.dto.QueryRechargeOrderDTO;
import com.yunsc.order.entity.YunscRechargeOrderEntity;
import com.yunsc.order.sevice.YunscRechargeOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.yunsc.common.utils.DateUtils.convertStringToSeconds;


@Service("yunscRechargeOrderService")
public class YunscRechargeOrderServiceImpl extends ServiceImpl<YunscRechargeOrderDao, YunscRechargeOrderEntity> implements YunscRechargeOrderService {


    @Resource
    private YunscUploadFileService uploadFileService;

    @Override
    public PageResult<YunscRechargeOrderEntity> queryRechargeOrder(QueryRechargeOrderDTO param, Integer storeId) {

        Page<YunscRechargeOrderEntity> pageResult = this.baseMapper.selectRechargeOrder(
                new Page<>(param.getPage(), param.getPageSize()),
                param,
                convertStringToSeconds(param.getBetweenTimeStart()),
                convertStringToSeconds(param.getBetweenTimeEnd()),
                storeId
        );
        pageResult.getRecords().forEach(order -> {
            order.getUser().setAvatarUrl(uploadFileService.queryFileUrlById(order.getUser().getAvatarId()));
        });

        return PageResult.formatPageResult(pageResult.getRecords(), param.getPage(), param.getPageSize(), pageResult.getTotal());

    }
}